package org.testmyapp.entities;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.testmyapp.persistence.BusinessObjectMarker;

@Entity
@IdClass(RefundPartPk.class)
public class RefundPart extends AbsProcessRelatedObject implements
		BusinessObjectMarker {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8435247017883540810L;

	public static String tableName = "RefundPart";

	@Id
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinTable(name = "bill_position_fk", joinColumns = {
			@JoinColumn(name = "billPosition_Nr_fk", referencedColumnName = "billPositionNr"),
			@JoinColumn(name = "bp_bill_fk", referencedColumnName = "bill_id_fk") })
	private BillPosition billPosition;
	@Id
	private int refundPartNr;
	@Temporal(value = TemporalType.DATE)
	private Date beginDate;
	@Temporal(value = TemporalType.DATE)
	private Date endDate;
	private int billingSum;
	private int refundSum;
	private TariffInstance tariffInstance;

	public BillPosition getBillPosition() {
		return billPosition;
	}

	public void setBillPosition(BillPosition billPosition) {
		this.billPosition = billPosition;
	}

	public int getRefundPartNr() {
		return refundPartNr;
	}

	public void setRefundPartNr(int refundPartNr) {
		this.refundPartNr = refundPartNr;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public TariffInstance getTariffInstance() {
		return tariffInstance;
	}

	public void setTariffInstance(TariffInstance tariffInstance) {
		this.tariffInstance = tariffInstance;
	}

	public int getBillingSum() {
		return billingSum;
	}

	public void setBillingSum(int billingSum) {
		System.out.println("billsingsum reset to: " + billingSum);
		this.billingSum = billingSum;
	}

	public int getRefundSum() {
		return refundSum;
	}

	public void setRefundSum(int refundSum) {
		this.refundSum = refundSum;
	}

	public RefundPart copy() {
		RefundPart rpCopy = new RefundPart();
		rpCopy.setBeginDate(new Date(this.getBeginDate().getTime()));
		rpCopy.setEndDate(new Date(this.getEndDate().getTime()));
		rpCopy.setBillPosition(this.getBillPosition());
		rpCopy.setProcessInstanceId(this.getProcessInstanceId());
		rpCopy.setRefundPartNr(this.getRefundPartNr());
		rpCopy.setTariffInstance(this.getTariffInstance());
		rpCopy.setBillingSum(this.getBillingSum());
		rpCopy.setRefundSum(this.getRefundSum());
		return rpCopy;
	}

	public String toString() {
		String result = "";
		result += "RefundPart: " + this.getRefundPartNr() + " (BillPosition: "
				+ this.getBillPosition().getBillPositionNr() + " of bill "
				+ getBillPosition().getBill().getBillNr()
				+ ") Summe/Erstattung: " + getBillingSum() + "/"
				+ getRefundSum();
		return result;
	}

}
